

# ./build.sh  10.10.111.188 test


param_verison=$(date +%F)
param_ip=${1}
param_env=${2}
param_ctiy=${3}

project_dir_path=$(
  cd $(dirname $0) 
  pwd
)


package_name=${project_dir_path##*/}
project_name=${project_dir_path##*/}
project_path=$(dirname "$PWD")
echo ""
echo "版本号:${param_verison}"
echo "项目名:${project_name}"
echo ""

if [[ $param_ip = '' ]]; then
  echo "请输入ip"
  exit 8
fi
if [[ $param_env = '' ]]; then
  echo "请输入环境"
  exit 8
fi

if [[ $param_ctiy != '' ]]; then
  package_name=$project_name-$param_ctiy
fi
echo "==================================开始=================================="




# build:test

echo "=================================编译结束============================================"

tar -zcvf ../dist/${package_name}-${param_verison}.tgz --exclude=.git --exclude=map --exclude=run --exclude=logs --exclude=node_modules .


echo "=================================打包结束============================================"

# cd ../dist/

if [[ $param_env == 'test' ]]; then # 开发环境

  scp ${project_path}/dist/${package_name}-${param_verison}.tgz admin@${param_ip}:~/${project_name}

  echo "=================================上传结束============================================"

  # ssh admin@${param_ip} "cp ${project_name}/${package_name}-${param_verison}.tgz ${project_name}s/;  cd ${project_name};"
  ssh admin@${param_ip} "cd ${project_name}; tar -zxvf ${package_name}-${param_verison}.tgz;npm run ${param_env};"

  echo "=================================重启结束============================================"

fi

if [[ $param_env == 'prod' ]]; then # 正式环境

  # scp ${project_path}/dist/${package_name}-${param_verison}.tgz root@10.10.111.184:~/backupsBh
  scp ${project_path}/dist/${package_name}-${param_verison}.tgz admin@10.10.111.3:~/backupsBh

  echo "=================================上传结束============================================"

fi

#
#
#
#
#=================================分割线============================================
#
#
#
#
#
#
#



# if [[ $param_verison = '' ]]; then
#   echo "请输入版本号"
#   exit 8
# fi

# project_dir_path=$(cd `dirname $0`; pwd)
# project_name=${project_dir_path##*/}

# echo ""
# echo "版本号:${target_time}"
# echo "项目名:${project_name}"
# echo ""
# echo $project_name
# if [[ $param2 != '' ]];then
# project_name=$param2
# else
# project_name="你好"
# exit 8
# fi
# echo $project_name
# echo $param2;
# echo $project_name
# if [ $param2 != '' ];then
# project_name=$param2
# else
# project_name="你好"
# fi
# echo $project_name
# echo $param2;
# project_path=$(cd `dirname $0`; pwd)
# project_name="${project_path##*/}"
# echo $project_path
# echo $project_name
# echo "\n\n当前路径：${current_dir_path}\n目录名称：${current_dir_name}\n项目路径：${project_dir_path}\n项目名称：${project_name}\n\n"
